home *** CD-ROM | disk | FTP | other *** search
/ MacFormat UK 199 / MF_UK_199_1.iso / pc / DiscContents / In the mag / Widgets / National Rail 0.02 / Widget / NationalRail.wdgt / NatRail.js < prev    next >
Encoding:
JavaScript  |  2008-07-08  |  27.6 KB  |  1,105 lines

  1. // This file was generated by Dashcode from Apple Inc.
  2. // You may edit this file to customize your Dashboard widget.
  3.  
  4. //
  5. // Function: load()
  6. // Called by HTML body element's onload event when the widget is ready to start
  7. //
  8. var depInter;
  9. var arrInter;
  10. var detInter;
  11. var stationPref;
  12. var refreshPeriod = 120000;
  13. var open = -1;
  14.  
  15. function load()
  16. {
  17.     setupParts();
  18.     stationPref = widget.preferenceForKey(widget.identifier+"-station");
  19.     if (!stationPref) stationPref="HUL";
  20.     document.getElementById("nrscode").value=stationPref;
  21.     loadPage("dep");
  22.     loadPage("arr");
  23.     depInter=self.setInterval("loadPage(\"dep\")",refreshPeriod);
  24.     arrInter=self.setInterval("loadPage(\"arr\")",refreshPeriod);
  25. }
  26.  
  27.  
  28. function loadPage(arr) 
  29. {
  30.     
  31.     document.getElementById("indicator").src = "Images/indicator.gif"
  32.     
  33.     var xmlhttp = new XMLHttpRequest();
  34.     if (xmlhttp != null) 
  35.     {
  36.         
  37.         xmlhttp.onreadystatechange = function()
  38.         {
  39.             if (xmlhttp.readyState==4)// && xmlhttp.status==200) 
  40.             {
  41.                 var ldbpage = xmlhttp.responseText;
  42.                 parseFunc(ldbpage,arr);
  43.             }
  44.             else
  45.             {
  46.                 
  47.             }
  48.         }
  49.     xmlhttp.open("GET","http://www.livedepartureboards.co.uk/ldb/sum"+arr+".aspx?T="+stationPref,true);
  50.     xmlhttp.send(null);
  51.     }
  52. }
  53.  
  54. function parseFunc(text,arr)
  55. {
  56.  
  57.     var start;
  58.     var end;
  59.     var line;
  60.     var count;
  61.     var platforms = -1;
  62.     var departure = new Array();
  63.     var destination = new Array();
  64.     var expected = new Array();
  65.     var operator = new Array();
  66.     var platform = new Array();
  67.     var details = new Array();
  68.     var display = "<table class=\"arrdep\">";
  69.     var disp = " <br>";
  70.     var station;
  71.     var circlecheck;
  72.     var information = "";
  73.     
  74.     if (text.indexOf("<th ><h3>PLATFORM</h3></th>") != -1) platforms=1;
  75.     
  76.     start=text.indexOf("class=\"arrivaltable\"");
  77.     start=text.indexOf("<tbody>",start);
  78.     end=text.indexOf("</tbody>",start);
  79.  
  80.     count=0;
  81.     line=0;
  82.     var st=start;
  83.     while (count != -1)
  84.     {
  85.         count=text.indexOf("<tr class=\"row",st);
  86.         circlecheck=text.substring(count,count+65);
  87.         if (circlecheck.indexOf("*** Circular route ***") != -1) line--;
  88.         st=count+1;
  89.         line++;
  90.     }
  91.     line--;
  92.     
  93.     station=text.substring(text.indexOf("<title>"),text.indexOf("</title>"));
  94.     if (station.indexOf("Error") != -1)
  95.     {
  96.         station=""
  97.     }
  98.     else
  99.     {
  100.         station=station.substring(station.indexOf(" - ")+3,station.indexOf(" Train Times"));
  101.     }
  102.     document.getElementById("station").innerHTML = station
  103.     
  104.     if (station != "")
  105.     {    
  106.         var st=0;
  107.         st=text.indexOf("<div class=\"maintmessages\">")
  108.         if (st != -1)
  109.         {
  110.             information=text.substring(text.indexOf("<div>",st)+5,text.indexOf("</div>",st))
  111.         }
  112.         else
  113.         {
  114.             information="";
  115.         }
  116.         document.getElementById("information").innerHTML = information
  117.     
  118.         count=1;
  119.         for (count=1;count<=line;count++)
  120.         {
  121.             departure[count]=getDept(start,end,count,text,platforms);
  122.         }
  123.  
  124.         count=1;
  125.         for (count=1;count<=line;count++)
  126.         {
  127.             destination[count]=getDest(start,end,count,text);
  128.         }
  129.     
  130.         count=1;
  131.         for (count=1;count<=line;count++)
  132.         {
  133.             expected[count]=getExpt(start,end,count,text,platforms,departure[count]);
  134.         }
  135.     
  136.         count=1;
  137.         for (count=1;count<=line;count++)
  138.         {
  139.             operator[count]=getOper(start,end,count,text);
  140.         }
  141.     
  142.         if (platforms != -1)
  143.         {
  144.             count=1;
  145.             for (count=1;count<=line;count++)
  146.             {
  147.                 platform[count]=getPlat(start,end,count,text);
  148.             }
  149.         }
  150.     }
  151.     
  152.     count=1;
  153.     for (count=1;count<=line;count++)
  154.     {
  155.         details[count]=getDetail(start,end,count,text);
  156.     }
  157.     
  158.     if (station != "")
  159.     {
  160.         count=1;
  161.         for (count=1;count<=line;count++)
  162.         {
  163.             //display=display+"<tr onclick=\"widget.openURL('http://www.livedepartureboards.co.uk/ldb/"+details[count]+"')\">"
  164.             display=display+"<tr style=\"height: 13px;\" onclick=\"loadDetailsPage('http://www.livedepartureboards.co.uk/ldb/"+details[count]+"','"+operator[count]+"')\">";
  165.             if (platforms != -1)
  166.             {
  167.                 if (expected[count].indexOf("L") != -1 || expected[count].indexOf("E") != -1)
  168.                 {
  169.                     if (expected[count].indexOf("L") != -1) display=display+"<td class=\"destplat\">"+destination[count]+"</td><td class=\"dept\">"+departure[count]+"</td><td class=\"plat\">"+platform[count]+"</td><td class=\"delay\">"+expected[count].substring(1,expected[count].length);
  170.                     if (expected[count].indexOf("E") != -1) display=display+"<td class=\"destplat\">"+destination[count]+"</td><td class=\"dept\">"+departure[count]+"</td><td class=\"plat\">"+platform[count]+"</td><td class=\"early\">"+expected[count].substring(1,expected[count].length);
  171.                 }
  172.                 else
  173.                 {
  174.                     display=display+"<td class=\"destplat\">"+destination[count]+"</td><td class=\"dept\">"+departure[count]+"</td><td class=\"plat\">"+platform[count]+"</td><td class=\"expt\">"+expected[count];
  175.                 }
  176.             }
  177.             else
  178.             {
  179.                 if (expected[count].indexOf("L") != -1 || expected[count].indexOf("E") != -1)
  180.                 {
  181.                     if (expected[count].indexOf("L") != -1) display=display+"<td class=\"dest\">"+destination[count]+"</td><td class=\"dept\">"+departure[count]+"</td><td class=\"delay\">"+expected[count].substring(1,expected[count].length);
  182.                     if (expected[count].indexOf("E") != -1) display=display+"<td class=\"dest\">"+destination[count]+"</td><td class=\"dept\">"+departure[count]+"</td><td class=\"early\">"+expected[count].substring(1,expected[count].length);
  183.                 }
  184.                 else
  185.                 {
  186.                     display=display+"<td class=\"dest\">"+destination[count]+"</td><td class=\"dept\">"+departure[count]+"</td><td class=\"expt\">"+expected[count];
  187.                 }
  188.             }
  189.             display=display+"</td><td><img class=\"operator\" src=\"Images/Logos/"+operator[count]+".png\" height=13></td></tr><tr><td colspan=5><hr></td></tr>";
  190.             //display=display+"</td><td><!--<img class=\"operator\" src=\"Images/Logos/"+operator[count]+".png\" width=46 height=13>--></td></tr><tr><td colspan=5><hr></td></tr>";
  191.         }
  192.         display=display+"</table>";
  193.         if (arr != "arr")
  194.         {
  195.             document.getElementById("content").innerHTML = display;
  196.             document.getElementById("scrollArea").object.refresh();
  197.         }
  198.         else
  199.         {
  200.             document.getElementById("content1").innerHTML = display;
  201.             document.getElementById("scrollArea1").object.refresh();
  202.         }
  203.     }
  204.     else
  205.     {
  206.         document.getElementById("content").innerHTML = "No information. Have you entered a valid code?";
  207.         document.getElementById("content1").innerHTML = "No information. Have you entered a valid code?";
  208.     }
  209.     document.getElementById("indicator").src = "Images/ind.gif"
  210. }
  211.  
  212. function getDept(begin,finish,number,text,platforms)
  213. {
  214.     var c=1;
  215.     var deptSt;
  216.     var deptEn;
  217.     var dept;
  218.     
  219.     deptSt=begin;
  220.     for (c=1;c<=number;c++)
  221.     {
  222.         deptSt=text.indexOf("<td class=\"cellone\" >",deptSt);
  223.         deptSt=text.indexOf("<td >",deptSt)+5;
  224.         if (platforms != -1) deptSt=text.indexOf("<td >",deptSt)+5;
  225.         deptEn=text.indexOf("</td>",deptSt);
  226.     }
  227.  
  228.     dept=text.substring(deptSt,deptEn);
  229.  
  230.     if (dept.indexOf(":") != -1)
  231.     {
  232.         dept=dept.substring(0,2)+dept.substring(3,6);
  233.     }
  234.  
  235.     return dept;
  236. }
  237.  
  238. function getExpt(begin,finish,number,text,platforms,dept)
  239. {
  240.     var c=1;
  241.     var exptSt;
  242.     var exptEn;
  243.     var expt;
  244.     var hour;
  245.     var dhour;
  246.     var min;
  247.     var dmin;
  248.     var green = -1;
  249.     
  250.     exptSt=begin;
  251.     for (c=1;c<=number;c++)
  252.     {
  253.         exptSt=text.indexOf("<td class=\"cellone\" >",exptSt);
  254.         exptSt=text.indexOf("<td >",exptSt)+5;
  255.         exptSt=text.indexOf("<td >",exptSt)+5;
  256.         if (platforms != -1) exptSt=text.indexOf("<td >",exptSt)+5;
  257.         exptEn=text.indexOf("</td>",exptSt);
  258.     }
  259.  
  260.     expt=text.substring(exptSt,exptEn);
  261.     if (expt.indexOf(":") != -1) 
  262.     { 
  263.         if (expt.indexOf("span") != -1)
  264.         {
  265.             exptSt=expt.indexOf(">")+1;
  266.             exptEn=expt.indexOf("</span>");
  267.             
  268.             hour=expt.substring(exptSt,exptSt+2)
  269.             min=expt.substring(exptSt+3,exptSt+5);
  270.             dhour=dept.substring(0,2);
  271.             dmin=dept.substring(2,4);
  272.             
  273.             if (hour < dhour || hour == dhour && min < dmin) green = 1;
  274.             
  275.             if (green == -1) expt="L"+hour+min;
  276.             if (green == 1) expt="E"+hour+min;
  277.         }
  278.         else
  279.         {
  280.             hour=expt.substring(0,2);
  281.             min=expt.substring(3,5);
  282.             dhour=dept.substring(0,2);
  283.             dmin=dept.substring(2,4);
  284.             
  285.             if (hour < dhour || hour == dhour && min < dmin) green = 1;
  286.             
  287.             if (green == -1) expt="L"+hour+min;
  288.             if (green == 1) expt="E"+hour+min;
  289.         }
  290.  
  291.     }
  292.         
  293.     if (expt.indexOf("Cancelled") != -1) expt="L"+expt
  294.     if (expt.indexOf("Delayed") != -1) expt="L"+expt
  295.  
  296.     return expt;
  297. }
  298.  
  299. function getOper(begin,finish,number,text)
  300. {
  301.     var c=1;
  302.     var operSt;
  303.     var operEn;
  304.     var oper;
  305.     
  306.     operSt=begin;
  307.     for (c=1;c<=number;c++)
  308.     {
  309.         operSt=text.indexOf("<td class=\"cellone\" >",operSt);
  310.         operSt=text.indexOf("atocCode=",operSt)+9;
  311.         operEn=text.indexOf("\">",operSt);
  312.     }
  313.  
  314.     oper=text.substring(operSt,operEn);
  315.     return oper;
  316. }
  317.  
  318. function getDetail(begin,finish,number,text)
  319. {
  320.     var c=1;
  321.     var detaSt;
  322.     var detaEn;
  323.     var deta;
  324.     
  325.     detaSt=begin;
  326.     for (c=1;c<=number;c++)
  327.     {
  328.         detaSt=text.indexOf("<td class=\"cellone\" >",detaSt);
  329.         detaSt=text.indexOf("<a href=\"train.aspx?",detaSt)+9;
  330.         detaEn=text.indexOf("\">",detaSt);
  331.     }
  332.  
  333.     deta=text.substring(detaSt,detaEn);
  334.     return deta;
  335. }
  336.  
  337. function getPlat(begin,finish,number,text)
  338. {
  339.     var c=1;
  340.     var platSt;
  341.     var platEn;
  342.     var plat;
  343.     
  344.     platSt=begin;
  345.     for (c=1;c<=number;c++)
  346.     {
  347.         platSt=text.indexOf("<td class=\"cellone\" >",platSt);
  348.         platSt=text.indexOf("<td >",platSt)+5;
  349.         platEn=text.indexOf("</td>",platSt);
  350.     }
  351.  
  352.     plat=text.substring(platSt,platEn);
  353.  
  354.     return plat;
  355. }
  356.  
  357. function getDest(begin,finish,number,text)
  358. {
  359.     var c=1;
  360.     var destSt;
  361.     var destEn;
  362.     var dest;
  363.     
  364.     destSt=begin;
  365.     for (c=1;c<=number;c++)
  366.     {
  367.         destSt=text.indexOf("<td class=\"cellone\" >",destSt)+21;
  368.         destEn=text.indexOf("</td>",destSt);
  369.     }
  370.  
  371.     dest=text.substring(destSt,destEn);
  372.     if (dest.substring(0,7) == "<a href")
  373.     {
  374.         destSt=dest.indexOf(">")+1;
  375.         destEn=dest.indexOf("</a>");
  376.         dest=dest.substring(destSt,destEn);
  377.         
  378.     }
  379.     return dest;
  380. }
  381.  
  382. //
  383. // Function: remove()
  384. // Called when the widget has been removed from the Dashboard
  385. //
  386. function remove()
  387. {
  388.     // Stop any timers to prevent CPU usage
  389.     // Remove any preferences as needed
  390.     // widget.setPreferenceForKey(null, createInstancePreferenceKey("your-key"));
  391.     clearInterval(arrInter);
  392.     clearInterval(depInter);
  393.     clearInterval(detInter);
  394. }
  395.  
  396. //
  397. // Function: hide()
  398. // Called when the widget has been hidden
  399. //
  400. function hide()
  401. {
  402.     // Stop any timers to prevent CPU usage
  403.     clearInterval(arrInter);
  404.     clearInterval(depInter);
  405.     clearInterval(detInter);
  406. }
  407.  
  408. //
  409. // Function: show()
  410. // Called when the widget has been shown
  411. //
  412. function show()
  413. {
  414.     // Restart any timers that were stopped on hide
  415.     loadPage("dep");
  416.     loadPage("arr");
  417.     depInter=self.setInterval("loadPage(\"dep\")",refreshPeriod);
  418.     arrInter=self.setInterval("loadPage(\"arr\")",refreshPeriod);
  419. }
  420.  
  421. //
  422. // Function: sync()
  423. // Called when the widget has been synchronized with .Mac
  424. //
  425. function sync()
  426. {
  427.     // Retrieve any preference values that you need to be synchronized here
  428.     // Use this for an instance key's value:
  429.     // instancePreferenceValue = widget.preferenceForKey(null, createInstancePreferenceKey("your-key"));
  430.     //
  431.     // Or this for global key's value:
  432.     // globalPreferenceValue = widget.preferenceForKey(null, "your-key");
  433. }
  434.  
  435. //
  436. // Function: showBack(event)
  437. // Called when the info button is clicked to show the back of the widget
  438. //
  439. // event: onClick event from the info button
  440. //
  441. function showBack(event)
  442. {
  443.     if (open != -1) closeDetails();
  444.     
  445.     var front = document.getElementById("front");
  446.     var back = document.getElementById("back");
  447.  
  448.     if (window.widget) {
  449.         widget.prepareForTransition("ToBack");
  450.     }
  451.  
  452.     front.style.display = "none";
  453.     back.style.display = "block";
  454.  
  455.     if (window.widget) {
  456.         setTimeout('widget.performTransition();', 0);
  457.     }
  458. }
  459.  
  460. //
  461. // Function: showFront(event)
  462. // Called when the done button is clicked from the back of the widget
  463. //
  464. // event: onClick event from the done button
  465. //
  466. function showFront(event)
  467. {
  468.     var front = document.getElementById("front");
  469.     var back = document.getElementById("back");
  470.  
  471.     if (window.widget) {
  472.         widget.prepareForTransition("ToFront");
  473.     }
  474.  
  475.     front.style.display="block";
  476.     back.style.display="none";
  477.  
  478.     if (window.widget) {
  479.         setTimeout('widget.performTransition();', 0);
  480.     }
  481.     loadPage("dep");
  482.     loadPage("arr");
  483. }
  484.  
  485. if (window.widget) {
  486.     widget.onremove = remove;
  487.     widget.onhide = hide;
  488.     widget.onshow = show;
  489.     widget.onsync = sync;
  490. }
  491.  
  492. function savePrefs(event)
  493. {
  494.     stationPref=document.getElementById("nrscode").value.toUpperCase();
  495.     document.getElementById("nrscode").value = stationPref;
  496.     widget.setPreferenceForKey(stationPref,widget.identifier+"-station");
  497.     showFront(event);
  498. }
  499.  
  500. function pressNrsCode(event)
  501. {
  502.     var keynumber=event.which;
  503.     if (keynumber == 13) savePrefs(event);
  504. }
  505.  
  506. function loadDetailsPage(details,operator)
  507. {
  508.     if (open == -1) openPane();
  509.     clearInterval(detInter);
  510.     detInter=self.setInterval("loadDetails('"+details+"','"+operator+"')",refreshPeriod);
  511.     setTimeout("loadDetails('"+details+"','"+operator+"')",300);
  512. }
  513.  
  514. function loadDetails(details,operator)
  515. {
  516.     var xmlhttp = new XMLHttpRequest();
  517.     if (xmlhttp != null) 
  518.     {
  519.         
  520.         xmlhttp.onreadystatechange = function()
  521.         {
  522.             if (xmlhttp.readyState==4)// && xmlhttp.status==200) 
  523.             {
  524.                 var detailspage = xmlhttp.responseText;
  525.                 detailsDisplay(detailspage,operator);
  526.             }
  527.             else
  528.             {
  529.                 
  530.             }
  531.         }
  532.     xmlhttp.open("GET",details,true);
  533.     xmlhttp.send(null);
  534.     }
  535. }
  536.  
  537. function detailsDisplay(detailspage,operator)
  538. {
  539.     var service;
  540.     var delaymessage;
  541.     var title;
  542.     var start;
  543.     var end;
  544.     var stop = new Array();
  545.     var schedule = new Array();
  546.     var expected = new Array();
  547.     var actual = new Array();
  548.     var display = "<table class=\"detail\"><tr><th>Station</th><th>Sched.</th><th>Expected</th><th>Actual</th></tr><tr><td colspan='4'><hr class=\"solid\"></td></tr>";
  549.     service=detailspage.substring(detailspage.indexOf("<title>"),detailspage.indexOf("</title>"));
  550.     if (service.indexOf("Error") != -1)
  551.     {
  552.         service="";
  553.     }
  554.     else
  555.     {
  556.         service=service.substring(service.indexOf(" - ")+3);
  557.     }
  558.     if (service.indexOf(":") != -1)
  559.     {
  560.         title="<table class=\"title\"><tr><td class=\"title\" style=\"width: 28px;\">"+service.substring(0,5)+"</td><td class=\"title\">"+service.substring(6)+"</td><td class=\"titleimage\"><img src=\"Images/Logos/"+operator+".png\"></td><tr><td colspan=\"3\"></td></tr></table>";
  561.     }
  562.     else
  563.     {
  564.         title="<table class=\"title\"><tr><td class=\"title\" style=\"width: 28px;\"></td><td class=\"title\">"+service+"</td><td class=\"titleimage\"><img src=\"Images/Logos/"+operator+".png\"></td><tr><td colspan=\"3\"></td></tr></table>";
  565.     }
  566.     document.getElementById("box").innerHTML=title;
  567.     
  568.     start=detailspage.indexOf("<div class=\"jpbody\">");
  569.     delaymessage=detailspage.substring(start,detailspage.indexOf("</div>",start));
  570.     if (delaymessage.indexOf(">This train") != -1 || delaymessage.indexOf("<br>We were") != -1)
  571.     {
  572.         if (delaymessage.indexOf(">This train") != -1)
  573.         {
  574.             delaymessage=delaymessage.substring(delaymessage.indexOf(">This train")+1,delaymessage.indexOf("<br>",delaymessage.indexOf(">This train")));
  575.         }
  576.         else
  577.         {
  578.             delaymessage=delaymessage.substring(delaymessage.indexOf(">We were")+1,delaymessage.indexOf("<br>",delaymessage.indexOf(">We were")));
  579.         }
  580.     }
  581.     else
  582.     {
  583.         delaymessage="";
  584.     }
  585.     document.getElementById("detailinformation").innerHTML=delaymessage;
  586.  
  587.     start=detailspage.indexOf("<table class=\"arrivaltable\"");
  588.     start=detailspage.indexOf("<tbody>",start);
  589.     end=detailspage.indexOf("</tbody>",start);
  590.     
  591.     var count=0;
  592.     var count2=0;
  593.     var line=0;
  594.     var st=0;
  595.     while (count != -1)
  596.     {
  597.         count=detailspage.indexOf("<tr class=\"row",st);
  598.         st=count+1;
  599.         line++;
  600.     }
  601.     line--;
  602.     
  603.     count=1;
  604.     for (count=1;count<=line;count++)
  605.     {
  606.         stop[count]=getDetailStop(start,end,count,detailspage);
  607.     }
  608.     
  609.     count=1;
  610.     for (count=1;count<=line;count++)
  611.     {
  612.         schedule[count]=getDetailSchedule(start,end,count,detailspage);
  613.     }
  614.     
  615.     count=1;
  616.     for (count=1;count<=line;count++)
  617.     {
  618.         expected[count]=getDetailExpected(start,end,count,detailspage,schedule[count]);
  619.         if (expected[count] == "No report*") expected[count]="No rprt*";
  620.     }
  621.     
  622.     count=1;
  623.     for (count=1;count<=line;count++)
  624.     {
  625.         actual[count]=getDetailActual(start,end,count,detailspage,schedule[count]);
  626.         if (actual[count] == "No report*") actual[count]="No rprt*";
  627.     }
  628.  
  629.     count=1;
  630.     for (count=1;count<=line;count++)
  631.     {
  632.         display=display+"<tr><td class='stop'>"+stop[count]+"</td><td class='detailtime'>"+schedule[count]+"</td>";
  633.         var colourcode=expected[count].substring(0,1)
  634.         switch (colourcode)
  635.         {
  636.             case "E":
  637.                 display=display+"<td class='detailexpgreen'>"+expected[count].substring(1)+"</td>";
  638.                 break;
  639.             case "L":
  640.                 display=display+"<td class='detailexpred'>"+expected[count].substring(1)+"</td>";
  641.                 break;
  642.             default:
  643.                 display=display+"<td class='detailexp'>"+expected[count]+"</td>";
  644.                 break;
  645.         }
  646.         var colourcode=actual[count].substring(0,1)
  647.         switch (colourcode)
  648.         {
  649.             case "E":
  650.                 display=display+"<td class='detailexpgreen'>"+actual[count].substring(1)+"</td>";
  651.                 break;
  652.             case "L":
  653.                 display=display+"<td class='detailexpred'>"+actual[count].substring(1)+"</td>";
  654.                 break;
  655.             default:
  656.                 display=display+"<td class='detailexp'>"+actual[count]+"</td>";
  657.                 break;
  658.         }
  659.         if (stop[count+1] == "") 
  660.         {
  661.             display=display+"</tr><tr><td colspan='4'></td></tr>"
  662.         }
  663.         else
  664.         {
  665.             display=display+"</tr><tr><td colspan='4'><hr></td></tr>"
  666.         }
  667.     }
  668.     
  669.     display=display+"</table>";
  670.     
  671.     document.getElementById("detailscontent").innerHTML=display;
  672.     document.getElementById("detailsArea").object.refresh();
  673. }
  674.  
  675. function getDetailStop(begin,finish,number,text)
  676. {
  677.     var c=1;
  678.     var St;
  679.     var En;
  680.     var ret;
  681.     var chk;
  682.     
  683.     St=begin;
  684.     for (c=1;c<=number;c++)
  685.     {
  686.         St=text.indexOf("<tr class=",St);
  687.         chk=text.substring(St,St+18)
  688.         if (chk.indexOf("row1a") != -1 || chk.indexOf("row2a") != -1)
  689.         {
  690.             St=text.indexOf("<td class=\"cellone",St+17);
  691.             ret=""            
  692.         }
  693.         else
  694.         {
  695.             St=text.indexOf("<td class=\"cellone",St+17);
  696.             St=text.indexOf(">",St)+1;
  697.             En=text.indexOf("</td>",St);
  698.             ret=text.substring(St,En);
  699.         }
  700.     }
  701.  
  702.     if (ret.substring(0,12).indexOf("<a href") != -1)
  703.     {
  704.         St=ret.indexOf(">")+1;
  705.         En=ret.indexOf("</a>");
  706.         ret=ret.substring(St,En);        
  707.     }
  708.     return ret;
  709. }
  710.  
  711. function getDetailSchedule(begin,finish,number,text)
  712. {
  713.     var c=1;
  714.     var St;
  715.     var En;
  716.     var ret;
  717.     var ad;
  718.     var chk;
  719.     
  720.     St=begin;
  721.     for (c=1;c<=number;c++)
  722.     {
  723.         St=text.indexOf("<tr class=",St);
  724.         chk=text.substring(St,St+18)
  725.         if (chk.indexOf("row1a") != -1 || chk.indexOf("row2a") != -1)
  726.         {
  727.             St=text.indexOf("<td class=\"cellone",St)+1;
  728.         }
  729.         else
  730.         {
  731.             St=text.indexOf("<td class=\"cellone",St)+1;
  732.             St=text.indexOf("<td class=\"cellone",St);
  733.         }
  734.         St=text.indexOf(">",St)+1;
  735.         if (text.substring(St,St+29).indexOf("Arr") != -1) ad="a";
  736.         if (text.substring(St,St+29).indexOf("Dep") != -1) ad="d";
  737.         St=text.indexOf("</div>",St)+6;
  738.         En=text.indexOf("</td>",St);
  739.     }
  740.  
  741.     ret=text.substring(St,En);
  742.     if (ret.indexOf(":") != -1) ret=ret.substring(0,2)+ret.substring(3,5);
  743.     return ret+ad;
  744. }
  745.  
  746. function getDetailExpected(begin,finish,number,text,sched)
  747. {
  748.     var c=1;
  749.     var St;
  750.     var En;
  751.     var ret;
  752.     var chk;
  753.     
  754.     St=begin;
  755.     for (c=1;c<=number;c++)
  756.     {
  757.         St=text.indexOf("<tr class=",St);
  758.         chk=text.substring(St,St+18)
  759.         if (chk.indexOf("row1a") != -1 || chk.indexOf("row2a") != -1)
  760.         {
  761.             St=text.indexOf("<td class=\"cellone",St)+1;
  762.         }
  763.         else
  764.         {
  765.             St=text.indexOf("<td class=\"cellone",St)+1;
  766.             St=text.indexOf("<td class=\"cellone",St);
  767.         }
  768.         St=text.indexOf("<td>",St)+4;
  769.         En=text.indexOf("</td>",St);
  770.     }
  771.  
  772.     ret=text.substring(St,En);
  773.     if (ret.indexOf("late") != -1)
  774.     {
  775.         St=ret.indexOf(">")+1;
  776.         En=ret.indexOf("</span>");
  777.         ret=ret.substring(St,En);
  778.     }
  779.     if (ret.indexOf(":") != -1)
  780.     {
  781.         var hr=ret.substring(0,2);
  782.         var min=ret.substring(3,5);
  783.         var shr=sched.substring(0,2);
  784.         var smin=sched.substring(2,4);
  785.         if (shr > hr || shr == hr && smin > min) ret="E";
  786.         if (shr < hr || shr == hr && smin < min) ret="L";
  787.         ret=ret+hr+min; 
  788.     }
  789.     if (ret.indexOf("Cancelled") != -1 || ret.indexOf("Delayed") != -1) ret="L"+ret 
  790.     if (ret == "_") ret=" ";
  791.     return ret;
  792. }
  793.  
  794. function getDetailActual(begin,finish,number,text,sched)
  795. {
  796.     var c=1;
  797.     var St;
  798.     var En;
  799.     var ret;
  800.     var chk;
  801.     
  802.     St=begin;
  803.     for (c=1;c<=number;c++)
  804.     {
  805.         St=text.indexOf("<tr class=",St);
  806.                 chk=text.substring(St,St+18)
  807.         if (chk.indexOf("row1a") != -1 || chk.indexOf("row2a") != -1)
  808.         {
  809.             St=text.indexOf("<td class=\"cellone",St)+1;
  810.         }
  811.         else
  812.         {
  813.             St=text.indexOf("<td class=\"cellone",St)+1;
  814.             St=text.indexOf("<td class=\"cellone",St);
  815.         }
  816.         St=text.indexOf("<td>",St)+4;
  817.         St=text.indexOf("<td>",St)+4;
  818.         En=text.indexOf("</td>",St);
  819.     }
  820.  
  821.     ret=text.substring(St,En);
  822.     if (ret.indexOf("late") != -1)
  823.     {
  824.         St=ret.indexOf(">")+1;
  825.         En=ret.indexOf("</span>");
  826.         ret=ret.substring(St,En);
  827.     }
  828.     if (ret.indexOf(":") != -1)
  829.     {
  830.         var hr=ret.substring(0,2);
  831.         var min=ret.substring(3,5);
  832.         var shr=sched.substring(0,2);
  833.         var smin=sched.substring(2,4);
  834.         if (shr > hr || smin > min) ret="E";
  835.         if (shr < hr || smin < min) ret="L";
  836.         ret=ret+hr+min; 
  837.     }
  838.     if (ret.indexOf("Cancelled") != -1 || ret.indexOf("Delayed") != -1) ret="L"+ret 
  839.     if (ret == "_") ret=" ";
  840.     return ret;
  841. }
  842.  
  843. function openPane()
  844. {
  845.     window.resizeTo(548,386);
  846.  
  847.     document.getElementById("details").style.visibility="visible";
  848.     
  849.     // Values you provide
  850.     var itemToMove = document.getElementById("details");    // replace with ID of element to move
  851.     var moveToLeftPosition = 280;                            // new left CSS value
  852.  
  853.     // Moving code
  854.     var originalLeft = parseInt(document.defaultView.getComputedStyle(itemToMove, null).getPropertyValue("left"));
  855.     var fadeHandler = function(a, c, s, f){ itemToMove.style.left = c + "px"; };
  856.     new AppleAnimator(500, 13, originalLeft, moveToLeftPosition, fadeHandler).start();
  857.  
  858.     // Values you provide
  859.     var itemToFadeIn = document.getElementById("details");    // replace with name of element to fade
  860.  
  861.     // Fading code
  862.     var fadeHandler = function(a, c, s, f){ itemToFadeIn.style.opacity = c; };
  863.     new AppleAnimator(500, 13, 0.0, 1.0, fadeHandler).start();
  864.     
  865.     setTimeout("openPaneAfterDelay()",500);
  866.     
  867.     open = 1;
  868. }
  869.  
  870. function openPaneAfterDelay()
  871. {
  872.     document.getElementById("closebutton").style.visibility="visible";
  873.     document.getElementById("detailsArea").style.visibility="visible";
  874.     document.getElementById("detailscontent").style.visibility="visible";
  875.     document.getElementById("detailinformation").style.visibility="visible";
  876.     document.getElementById("box").style.visibility="visible";
  877. }
  878.  
  879. function closeDetails()
  880. {
  881.     document.getElementById("closebutton").style.visibility="hidden";
  882.     document.getElementById("detailsArea").style.visibility="hidden";
  883.     document.getElementById("detailscontent").style.visibility="hidden";
  884.     document.getElementById("detailinformation").style.visibility="hidden";
  885.     document.getElementById("box").style.visibility="hidden";
  886.  
  887.  
  888. // Pane
  889.     var itemToMove = document.getElementById("details");    // replace with ID of element to move
  890.     var moveToLeftPosition = 30;                            // new left CSS value
  891.     var originalLeft = parseInt(document.defaultView.getComputedStyle(itemToMove, null).getPropertyValue("left"));
  892.     var fadeHandler = function(a, c, s, f){ itemToMove.style.left = c + "px"; };
  893.     new AppleAnimator(500, 13, originalLeft, moveToLeftPosition, fadeHandler).start();
  894.     
  895.     var itemToFadeOut = document.getElementById("details");    // replace with name of element to fade
  896.     var fadeHandler = function(a, c, s, f){ itemToFadeOut.style.opacity = c; };
  897.     new AppleAnimator(500, 13, 1.0, 0.0, fadeHandler).start();
  898.     
  899.     setTimeout("closeDetailsAfterDelay()",400);
  900.     clearInterval(detInter);
  901.     open=-1;
  902. }
  903.  
  904. function closeDetailsAfterDelay()
  905. {
  906.     window.resizeTo(298,386)
  907.     document.getElementById("box").innerHTML="";
  908.     document.getElementById("detailscontent").innerHTML="";
  909.     document.getElementById("detailsArea").object.refresh();
  910.     
  911. }
  912.  
  913. function term(event)
  914. {
  915.     termload("http://www.heathrowairport.com/portal/page/General/Heathrow%5EGeneral%5EFlight+information%5ELive+flight+departures/","dep")
  916.     termload("http://www.heathrowairport.com/portal/page/General/Heathrow%5EGeneral%5EFlight+information%5ELive+flight+arrivals/","arr")
  917. }
  918.  
  919. function termload(url,ad)
  920. {
  921.     if (stationPref == "HWV" || stationPref == "HXX" || stationPref == "HAF")
  922.     {
  923.         var xmlhttp = new XMLHttpRequest();
  924.         if (xmlhttp != null) 
  925.         {    
  926.             xmlhttp.onreadystatechange = function()
  927.             {
  928.                 if (xmlhttp.readyState==4)// && xmlhttp.status==200) 
  929.                 {
  930.                     var ttext = xmlhttp.responseText;
  931.                     tparse(ttext,ad);
  932.                 }
  933.                 else
  934.                 {
  935.                 
  936.                 }
  937.             }
  938.         xmlhttp.open("GET",url,true);
  939.         xmlhttp.send(null);
  940.         }
  941.     }
  942. }
  943.  
  944. function tparse(ttext,arde)
  945. {
  946.     var st;
  947.     var en;
  948.     var tablecontent;
  949.     var display="<table class=\"terminal\"><tr><td style='width: 19px;'></td><td style='width: 33px;'></td><td style='width: 80px;'></td><td style='width: 58px;'></td><td style='width: 60px;'></td></tr>";
  950.     
  951.     st=ttext.indexOf("<table id=\"time");
  952.     st=ttext.indexOf("<tbody>",st)+7;
  953.     en=ttext.indexOf("</table>",st)-1;
  954.     tablecontent=ttext.substring(st,en);
  955.     
  956.     display=display+tablecontent+"</table>";
  957.     
  958.     if (arde == "dep")
  959.     {
  960.         document.getElementById("content").innerHTML = display;
  961.         document.getElementById("scrollArea").object.refresh();
  962.     }
  963.     else
  964.     {
  965.         document.getElementById("content1").innerHTML = display;
  966.         document.getElementById("scrollArea1").object.refresh();
  967.     }
  968. }
  969.  
  970. function stationSearch(event)
  971. {
  972.     var keynumber=event.which;
  973.     if (keynumber == 13) stationLookup(event);
  974. }
  975.  
  976. function stationLookup(event)
  977. {
  978.     var searchString;
  979.     var firstPipe;
  980.     var secondPipe=0;
  981.     var pipeContents="";
  982.     var pipeContentsUpper="";
  983.     var positiveArray = new Array();
  984.     sortedArray = new Array();
  985.     sortedCount = 0;
  986.     var arrayCount=0;
  987.     var menu="";
  988.     var beginning;
  989.     
  990.     //Get string to search for
  991.     searchString=document.getElementById("stationentry").value.toUpperCase();
  992.     
  993.     while (secondPipe != -1)
  994.     {
  995.         //Get position of first pipe
  996.         firstPipe=stationList.indexOf("|",secondPipe)+1;
  997.     
  998.         //Get position of second pipe
  999.         secondPipe=stationList.indexOf("|",firstPipe);
  1000.     
  1001.         //Get pipe contents
  1002.         pipeContents=stationList.substring(firstPipe,secondPipe);
  1003.         
  1004.         //Check if the pipe contents contain the string we're looking for
  1005.         pipeContentsUpper=pipeContents.toUpperCase();    
  1006.         if (pipeContentsUpper.indexOf(searchString) != -1)
  1007.         {
  1008.             //if it does add the pipe contents to an array of positive matches otherwise ignore
  1009.             arrayCount++;
  1010.             positiveArray[arrayCount]=pipeContents;
  1011.         }        
  1012.     }
  1013.     arrayCount--;
  1014.     
  1015.     var i=0;
  1016.     sortedCount=1;
  1017.     for (i=1;i<=arrayCount;i++)
  1018.     {
  1019.         if (searchString == positiveArray[i].substring(0,3))
  1020.         {
  1021.             sortedArray[sortedCount]=positiveArray[i];
  1022.             arrayCount=rebuildPositive(positiveArray,i,arrayCount);
  1023.             sortedCount++;
  1024.         }
  1025.         else
  1026.         {
  1027.             if (positiveArray[i].substring(4).toUpperCase() == searchString)
  1028.             {
  1029.                 sortedArray[sortedCount]=positiveArray[i];
  1030.                 arrayCount=rebuildPositive(positiveArray,i,arrayCount);
  1031.                 sortedCount++;
  1032.             }
  1033.         }
  1034.     }
  1035.  
  1036.     var i=0;
  1037.     for (i=1;i<=arrayCount;i++)
  1038.     {
  1039.         beginning = positiveArray[i].substring(4,searchString.length+4).toUpperCase();
  1040.         if (beginning == searchString)
  1041.         {
  1042.             sortedArray[sortedCount]=positiveArray[i];
  1043.             arrayCount=rebuildPositive(positiveArray,i,arrayCount);
  1044.             sortedCount++;
  1045.             i--;
  1046.         }
  1047.     }
  1048.     
  1049.     var i=0;
  1050.     for (i=1;i<=arrayCount;i++)
  1051.     {
  1052.         sortedArray[sortedCount]=positiveArray[i];
  1053.         sortedCount++;
  1054.     }
  1055.     sortedCount--;
  1056.     
  1057.     // create a menu of the sorted results
  1058.     if (sortedCount > 0)
  1059.     {
  1060.         var i=0;
  1061.         for (i=1;i<=sortedCount;i++)
  1062.         {
  1063.             menu=menu+"<option id=\""+i+"\">"+sortedArray[i].substring(4)+"</option>";
  1064.         }
  1065.         //document.getElementById("popup").object.setEnabled(true);
  1066.         if (document.getElementById("nrscode").value == sortedArray[1].substring(0,3)) savePrefs(event);
  1067.         document.getElementById("nrscode").value = sortedArray[1].substring(0,3);
  1068.         document.getElementById("stationentry").value = sortedArray[1].substring(4);
  1069.         document.getElementById("popup").innerHTML = menu;
  1070.     }
  1071.     else
  1072.     {
  1073.         //document.getElementById("popup").object.setEnabled(false);
  1074.         document.getElementById("popup").innerHTML = menu;
  1075.     }
  1076. }
  1077.  
  1078. function rebuildPositive(array,i,arrayCount)
  1079. {
  1080.     var count=1;
  1081.     arrayCount--;
  1082.     for (count=1;count<=arrayCount;count++)
  1083.     {
  1084.         if (count < i) array[count] = array[count];
  1085.         if (count >= i) array[count] = array[count+1];
  1086.     }
  1087.     return arrayCount;
  1088. }
  1089.  
  1090. function setStationSearch(event)
  1091. {
  1092.     var popupValue = document.getElementById("popup");
  1093.     popupValue = popupValue.value
  1094.     
  1095.     var i=0;
  1096.     for (i=1;i<=sortedCount;i++)
  1097.     {
  1098.         if (popupValue == sortedArray[i].substring(4))
  1099.         {
  1100.             document.getElementById("nrscode").value = sortedArray[i].substring(0,3);
  1101.             document.getElementById("stationentry").value = sortedArray[i].substring(4);
  1102.         }
  1103.     }
  1104. }
  1105.